<?php
/**
 * 自定义广告位控件
 * adcontroller.php
 * 参数设定：
 * 0 表示首页独家策划第六张
 * 1 表示首页/频道页焦点图左侧广告位
 * 2 表示ajax 获取的控件数据 文章页 rightNow页 
 * Create on 
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\common;

class AdController extends \haibao\cms\business\control\Base{
	
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	
	/**
	 * 获取模版内容
	 * @param : String $content
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		$type = 0;
		if(isset($controlData['manual']['type'])) $type = $controlData['manual']['type'];

		$showAutoData = false;
		$parameterValue = array();
		
		if($type == 1){
			
			if($controlData['auto']){
				$showAutoData = true;
				foreach($controlData['auto'] as $data){
					$parameterValue = json_decode($data['ParameterValue']);
				}
			}
		}elseif($type == 2){
			
			isset($controlData['manual']['channel'])?$channel = $controlData['manual']['channel']:$channel='www';
			if($controlData['auto']){
				foreach($controlData['auto'] as $data){
					$value = json_decode($data['ParameterValue'],true);
					if(isset($value['selectData']) && $value['selectData'] == $channel){
						$showAutoData = true;
						$parameterValue = $value;
						break;
					}
				}
			}
		}elseif($type == 3){
			isset($controlData['manual']['channel'])?$channel = $controlData['manual']['channel']:$channel='cate';
			if($controlData['auto']){
				foreach($controlData['auto'] as $data){
					$value = json_decode($data['ParameterValue'],true);
					if(isset($value['selectData']) && $value['selectData'] == $channel){
						$showAutoData = true;
						$parameterValue = $value;
						break;
					}
				}
			}
		}else{

			if($controlData['auto']){
				foreach($controlData['auto'] as $data){
					$parameterValue = json_decode($data['ParameterValue'],true);
				}
			}
		}
		$this->assign('parameterValue',$parameterValue);
		$this->assign('showAutoData',$showAutoData);
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		return $this->getHtml($path);
	}
}